package online.heycm.multipledb.service;

import online.heycm.multipledb.domain.logistics.entity.LogisticsLogEntity;
import online.heycm.multipledb.domain.logistics.service.ILogisticsLogService;
import online.heycm.multipledb.domain.order.entity.OrderLogEntity;
import online.heycm.multipledb.domain.order.service.IOrderLogService;
import online.heycm.multipledb.domain.pay.entity.PayTransLogEntity;
import online.heycm.multipledb.domain.pay.service.IPayTransLogService;
import online.heycm.multipledb.domain.user.entity.UserProfileEntity;
import online.heycm.multipledb.domain.user.service.IUserProfileService;
import online.heycm.multipledb.service.dto.UserDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 聚合服务
 */
@RestController
@RequestMapping("/agg")
public class AggregateService {

    @Autowired
    private IUserProfileService userProfileService;
    @Autowired
    private IOrderLogService orderLogService;
    @Autowired
    private IPayTransLogService payTransLogService;
    @Autowired
    private ILogisticsLogService logisticsLogService;


    @PostMapping("/user")
    public String createUser(@RequestBody UserDTO dto) {
        UserProfileEntity user = new UserProfileEntity();
        user.setUsername(dto.getUsername());
        user.insert();
        userProfileService.save(user);
        return "ok";
    }

    @GetMapping("/user/{uid}")
    public String getUser(@PathVariable Integer uid) {
        UserProfileEntity user = userProfileService.getById(uid);
        return user == null ? "查无此人" : user.toString();
    }

    @GetMapping("/other")
    public String other() {
        List<UserProfileEntity> users = userProfileService.list();
        List<OrderLogEntity> orders = orderLogService.list();
        List<PayTransLogEntity> pays = payTransLogService.list();
        List<LogisticsLogEntity> logs = logisticsLogService.list();
        return "ok";
    }
}
